/* !
 * elasticlunr.utils
 * Copyright (C) @YEAR Oliver Nightingale
 * Copyright (C) @YEAR Wei Song
 */

export default function (elasticlunr) {
  /**
   * A namespace containing utils for the rest of the elasticlunr library
   */
  elasticlunr.utils = {};

  /**
   * Print a warning message to the console.
   *
   * @param {String} message The message to be printed.
   * @memberOf Utils
   */
  elasticlunr.utils.warn = (function (global) {
    return function (message) {
      if (global && global.console && global.console.warn) {
        global.console.warn(message);
      }
    };
  })(this);

  /**
   * Convert an object to string.
   *
   * In the case of `null` and `undefined` the function returns
   * an empty string, in all other cases the result of calling
   * `toString` on the passed object is returned.
   *
   * @param {object} obj The object to convert to a string.
   * @return {String} string representation of the passed object.
   * @memberOf Utils
   */
  elasticlunr.utils.toString = function (obj) {
    if (obj === void 0 || obj === null) {
      return '';
    }

    return obj.toString();
  };
};
